
#include "Common/Errors.h"
#include "Common/Extras.h"
#include "Runtime.Low/Pipeline.h"

#undef GetEnvironmentVariable
#undef CreateWindow
#include "PipelineManager.h"
#include "../CastingRoutines.h"

using namespace ttg::extras::serialization;

extern "C"
{
	//Creates and registers pipeline.
	//Returns ID of created pipeline.
	__declspec(dllexport) ttg::math::uint64 __stdcall createPipeline(void *serialized_pipeline,
																	 ttg::math::uint64 size_in_bytes)
	{
		try
		{
			ByteDeSerializer deserializer(serialized_pipeline, (size_t)size_in_bytes);
			ttg_internal::pipeline::LitePipelineInfo pipeline;
			deserializer.deserializeObject(pipeline, "pipeline");
			return ttg_internal::utils::PipelineManager::getRef()->createPipeline(pipeline);
		}
		catch (System::Exception ^ex)
		{
			System::Console::WriteLine(ex->Message);
			return 0;
		}
	}

	//Releases previously created pipeline.
	__declspec(dllexport) void __stdcall releasePipeline(ttg::math::uint64 ID)
	{
		try
		{ ttg_internal::utils::PipelineManager::getRef()->releasePipeline(ID); }
		catch (System::Exception ^ex)
		{ System::Console::WriteLine(ex->Message); }
	}
}
